package text.textToHbase.tyouiifan;

import static org.junit.Assert.*;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import textToHbase.tyouiifan.HbaseAccess;

public class TestHbaseAccess {

	static HbaseAccess ha;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		ha = new HbaseAccess("testTable");
	}

	@Before
	public void setUp() throws Exception {
	}

	String key = "key1";
	String family = "fam2";
	String colum = "col1";
	String value = "value1";

	@Test
	public final void testPutKeyValue() {
		KeyValue kv = new KeyValue(Bytes.toBytes(key), Bytes.toBytes(family),
				Bytes.toBytes(colum), Bytes.toBytes(value));
		ha.put(kv);
		assertTrue(ha.get(key, family, colum).equals(value));
	}

	@Test
	public final void testPutStringStringStringString() {
		ha.put(key, family, colum, value);
		assertTrue(ha.get(key, family, colum).equals(value));
	}

	// @Test
	// public final void testPutStringString() {
	// ha.put(key,value);
	// assertTrue(ha.get(key).equals(value));
	// }

	@Test
	public final void testGetStringStringString() {
		System.out.println(ha.get(key, family, colum));
		assertTrue(ha.get(key, family, colum).equals(value));
	}

	@Test
	public final void testGetString() {
		boolean test = false;
		KeyValue[] r = ha.get(key);
		System.out.println(r.length);

		for (int i = 0; i < r.length; i++) {
			System.out.println(Bytes.toString(r[i].getValue()));
		}

		assertTrue(test); // TODO
	}

}
